import requests
import json

import unittest
from parameterized import parameterized


def make_data():
    temp = []
    with open("data.json", "r", encoding="utf-8") as f:
        f_json = json.load(f)
        for item in f_json:
            temp.append(tuple(dict(item).values()))
    print(temp)
    return temp


class TestLogin(unittest.TestCase):

    @parameterized.expand(make_data)
    def test00_login(self, status_code, content_type, username, password, verify_code, status, msg):
        session = requests.Session()

        # resp = session.get("http://localhost/index.php?m=Home&c=User&a=verify")

        self.assertEqual(status_code, resp.status_code)
        self.assertIn(content_type, resp.headers.get("Content-Type"))

        data = {
            "username": username,
            "password": password,
            "verify_code": verify_code,
        }

        # resp = session.post("http://localhost/index.php?m=Home&c=User&a=do_login", data=data)
        self.assertEqual(status_code, resp.status_code)
        self.assertEqual(status, resp.json().get("status"))
        self.assertEqual(msg, resp.json().get("msg"))


if __name__ == '__main__':
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TestLogin))
    runner = unittest.TextTestRunner()
    runner.run(suite)
